<style lang="less">
    @import "regularApproveDetail.less";
</style>
<template>
    <div class="detail">
        <Softphone :isCallOut="isCallOut" :callNumber="callNumber"  />
        <div class="caseNoticeNumber" @click="showCaseNotice" v-if="isCheck && noticeNumberVisible && noticeNumber>0">
            <span class="notice">{{noticeNumber}}</span>
        </div>
        <back-top :height="100" :duration="250" style="padding: 10px" :bottom="500" :right="0">
            <i-button type="primary" shape="circle" size="default" >返回顶端</i-button>
        </back-top>
        <Row>
            <remind v-model="remindVisible"
                    @afterSubmit="afterRemindSubmit"
                    @beforeSubmit="beforeRemindSubmit"
                    :approve-record="remindApproveRecord"
                    :is-check="isCheck"
                    :isDealerCallBack="this.isDealerCallBack"/>
                <Card>
                <Row type="flex" justify="start" align="middle">
                    <Col>
                        <Row>
                            <div class="line">
                                <Button @click="closeThis" type="primary" icon="md-return-left" >返回</Button>
                                <Button type="primary" icon="md-photos" id="imgBtn">
                                    <DynamicLink component="projects/basic/pages/image/file-audit/createFileAudit"
                                                 :is-full="true" page-title="影像资料" :params="{auditParam:this.auditParam,operate:this.isCheck,businessDic:[{value:'orderApply,creditApprove,',title:'零售审批'},{value:'assetsChange',title:'资产变更'},{value:'orderReconsider',title:'复议申请'}],pageTitle:detailParams.applyNo}"
                                                 name="影像资料"
                                    />
                                </Button>
                                <credit-pboc :credit-score="tortoiseCreditScore" :apply-no="this.detailParams.applyNo"/>
                                <Button @click="externalData" type="primary" icon="md-information">外部数据</Button>
                                <Button @click="addMessage" type="primary" icon="md-send" v-if="isCheck">添加留言</Button>
                                <Button @click="addPaper" type="primary" icon="md-camera" v-if="isCheck" >审批补件</Button>
                                <Button @click="dayBook" type="primary" icon="md-information" v-if="isCheck">流水解析</Button>
                            </div>
                        </Row>
                    </Col>
                </Row>
                <Row>
                    <Tabs value="name1" type="card" :animated="true" @on-click="clickTab">
                        <TabPane label="贷前识别" icon="md-cash" name="name1"
                                 :linkOption="{component:'projects/afs-core-business/pages/case/approve/task-detail/pre-loan-identify/preLoanIdentify',
                                 isFull:true,
                                 withSsoToken:true,
                                 params:{taskId:this.detailParams.taskId,applyNo:this.detailParams.applyNo},
                                 pageTitle:'贷前识别'}">
                            <pre-loan-identify ref="preLoanIdentify" :url="tortoiseLinkConfig.beforeApplyDiscernUrl" :apply-no="this.detailParams.applyNo" :is-check="isCheck"></pre-loan-identify>
                        </TabPane>

                        <TabPane label="车贷信息" icon="md-car" name="name2"
                                 :linkOption="{component:'projects/afs-core-business/pages/case/infomationDetail/asset/assetDetail',
                                 isFull:true,
                                 params:{applyNo:this.detailParams.applyNo},
                                 pageTitle:'车贷信息'}" >
                            <asset-detail
                            ref="assetDetail"
                            :apply-no="this.detailParams.applyNo"
                            :is-check="isCheck"
                            :tabName="tabName"
                            @additionChange="additionChange"
                            :isAppear="this.detailParams.isAppear"
                            ></asset-detail>
                        </TabPane>
                        <TabPane label="客户信息" icon="md-people" name="name3"
                                 :linkOption="{component:'projects/afs-core-business/pages/case/infomationDetail/cust/applyCustomerDetail',
                                 isFull:true,
                                 params:{applyNo:this.detailParams.applyNo},
                                 pageTitle:'客户信息'}">
                            <apply-customer-detail
                            ref="applyCustomerDetail"
                            :apply-no="this.detailParams.applyNo"
                            :is-check="isCheck"
                            :tabName="tabName"
                            :isAppear="this.detailParams.isAppear"
                            ></apply-customer-detail>
                        </TabPane>
                        <TabPane label="信贷分析" icon="md-analytics" name="name4"
                                 :linkOption="{component:'projects/afs-core-business/pages/case/approve/task-detail/loan-analyze/loanAnalyze',
                                 isFull:true,
                                 params:{firstTrail:this.detailParams.firstTrail,lastTrail:this.detailParams.lastTrail,applyNo:this.detailParams.applyNo,isCheck:this.isCheck,isFire:this.isFire,stageId:this.detailParams.stageId,firstTrail:this.detailParams.firstTrail},
                                 pageTitle:'信贷分析'}"
                        >
                            <loan-analyze ref="loanAnalyze" :apply-no="detailParams.applyNo"
                                          :stage-id="detailParams.stageId"
                                          :is-check="isCheck"
                                          :is-fire="isFire"
                                          :is-lung="isLung"
                                          :business-state-in="scene"
                                          @on-set-approve="setApproveRecord" @whenClose="whenClose"
                                          :tabName="tabName"
                                          ></loan-analyze>
                        </TabPane>
                    </Tabs>
                </Row>
            </Card>
        </Row>     

        <Modal v-model="showUpload" :width="1100">
            <fileOperation  :uploadParam="uploadParam"  :isInt="canUpload" :path="path" ></fileOperation>
        </Modal>
    </div>

</template>



<script>
    import fileAudit from "@/projects/basic/pages/image/file-audit/fileAudit";
    import Softphone from "_p/basic/pages/softphone/softphone";
    import CaseNotice from '@/projects/afs-core-business/pages/home/CaseNotice.vue';
    import circleLoading from "_c/circle-loading/circle-loading.vue";
    import assetDetail from "../../../infomationDetail/asset/assetDetail.vue";
    import applyCustomerDetail from "../../../infomationDetail/cust/applyCustomerDetail.vue";
    import loanAnalyze from "../loan-analyze/loanAnalyze.vue";
    import PreLoanIdentify from "../pre-loan-identify/preLoanIdentify";
    import Remind from "../../remind/remind";
    import {
        setStatusIsOpen
    } from "@/projects/afs-core-business/api/afs-case/approve/approveTask";
    import CreditPboc from "../../approve-task/creditPboc";
    import {getTortoiseLinkConfig,getNewestApplyNotice} from "../../../../../api/afs-case/tortoise/tortoise";
    import fileOperation from "_p/basic/pages/image/upload-file/fileOperation.vue";
    import {dayBookResolve} from "../../../../../api/afs-case/approve/approveTask";
    import { mapGetters } from "vuex";
    import { getCaseNoticeInfoByApplyNo,markCaseNoticeInfoAsRead,processCaseNotice }
        from '_p/afs-core-business/api/afs-case/approve-notice/caseNoticeInfo';
    export default {
        name: "regular-approve-detail",
        components: {
            CreditPboc,
            Remind,
            PreLoanIdentify,
            circleLoading,
            loanAnalyze,
            assetDetail,
            Softphone,
            applyCustomerDetail,
            fileAudit,
            fileOperation,
            CaseNotice
        },
        data() {
            return {
                isCallOut:false,
                callNumber:'18407617866',
                detailParams:{},
                tabName:"name1",
                isShow:true,
                loading: true,
                isLung: true,
                scene: "",
                operationLoading: false,
                noticeNumberVisible:false,
                isDealerCallBack:false,
                refreshTime:-1,
                noticeInfoList:[
                    {
                        id:"",
                        noticeType:"",
                        applyNo:"",
                        notice:"",
                        receivedBy:"",
                        isRead:"",
                        result:""
                    }
                ],
                noticeNumber:0,
                currentNotice:{
                    id:"",
                    noticeType:"",
                    applyNo:"",
                    notice:"",
                    receivedBy:"",
                    isRead:"",
                    result:""
                },
                applyTags: [
                    {
                        name:"标签1",
                        tagColor:"success"
                    },
                    {
                        name:"标签2",
                        tagColor:"error"
                    },
                    {
                        name:"标签3",
                        tagColor:"success"
                    },
                    {
                        name:"标签4",
                        tagColor:"error"
                    },
                    {
                        name:"标签5",
                        tagColor:"success"
                    }
                ],

                data: {},
                total: 0,
                remindVisible : false,
                remindApproveRecord:{
                    applyNo: '',
                    stageId: '',
                    approveRemark: '',
                    useScene:'approve'
                },
                isCheck: true,
                isFire: true,
                auditParam:{
                    busiNo:'',
                    belongNo:'',
                    busiNode:"orderApply"},
                tortoiseLinkConfig:{
                    beforeApplyDiscernUrl:"",
                    outsideDataQueryUrl:""
                },
                tortoiseApplyNoticeData:{},
                tortoiseCreditScore:" / / ",
                //附件部分
                uploadParam: {
                    busiNo: "",
                    belongNo: "",
                    busiType: "",
                    busiData: {}
                },
                canUpload:false,
                path:"case",
                showUpload:false,
            };
        },
        computed:{
            ...mapGetters(['userInfo']),
        },
        methods: {
            initLinkConfig(){
                let params = {
                    applyNo: this.detailParams.applyNo
                }
                getTortoiseLinkConfig(params).then(res=>{
                    if(res.code == "0000") {
                        this.tortoiseLinkConfig = res.data;
                        this.tortoiseLinkConfig.beforeApplyDiscernUrl = this.tortoiseLinkConfig.beforeApplyDiscernUrl + "&token=" + this.$store.getters.sso_access_token;
                    }
                })
            },
            initNewestTortoiseApply() {
                let params = {
                    applyNo: this.detailParams.applyNo
                }
                getNewestApplyNotice(params).then(res => {
                    if(res.code == "0000"){
                        this.tortoiseApplyNoticeData = res.data;
                        if(this.tortoiseApplyNoticeData){
                            this.tortoiseCreditScore = (this.tortoiseApplyNoticeData.customerCreditScore || "")
                                    + " / " + (this.tortoiseApplyNoticeData.sponsorCreditScore || "")
                                    + " / " + (this.tortoiseApplyNoticeData.bondCreditScore || "");
                        }
                    }
                });
            },
            clickTab(name){
                this.tabName=name;
            },
            closeThis() {
                this.whenClose();
                window.close();
            },
            externalData() {
                window.open(this.tortoiseLinkConfig.outsideDataQueryUrl);
            },
            addMessage() {
                this.remindVisible = true;
            },
            additionChange(val) {
                this.$refs.loanAnalyze.changeAddition(val);
            },
            afterRemindSubmit(type,approveRecord,remind){
                if(type == "save"){
                    this.$refs.loanAnalyze.queryRemind();
                }else if(type == "reject"){
                    this.whenClose();
                    window.close();
                }else if(type == "parse"){
                    this.$refs.loanAnalyze.queryRemind();
                }
            },
            beforeRemindSubmit(type,record,remind){
                if(type == "reject"){
                    this.$refs.loanAnalyze.setRemindRemark();
                }
            },
            addPaper() {
                this.uploadParam.busiNo=this.detailParams.applyNo;
                this.uploadParam.belongNo=this.detailParams.applyNo;
                this.uploadParam.busiType="creditApprove";
                this.showUpload=true;
                this.canUpload=true;

            },
            dayBook(){
                let params = {
                    applyNo: this.detailParams.applyNo
                };
                this.$Spin.show();
                dayBookResolve(params).then(res=>{
                    this.$Message.info("操作成功！");
                }).finally(()=>{
                    this.$Spin.hide();
                });
            },
            setApproveRecord(approveRecord){
                this.remindApproveRecord.approveRemark = approveRecord.approveRemark;
            },
            whenClose(){
                this.afs.afsEmit(this,"flushData");
            },
            //add by gjq 更新打开状态
            updateStatusIsOpen(){
                let params="";
                params={
                    approveStaff:this.detailParams.disposeCode,
                    stageId:this.detailParams.stageId,
                    processType:this.detailParams.processType,
                    applyNo:this.detailParams.applyNo
                }
                setStatusIsOpen(params).then(res => {
                    if (res.code === "0000") {
                    }
                });
            },
            getNoticeInfoByApplyNo(){
                let params={
                    applyNo:this.detailParams.applyNo
                }
                getCaseNoticeInfoByApplyNo(params).then((res) => {
                    if(res.code === '0000'){
                        this.noticeInfoList=res.data.records;
                        this.noticeInfoList.forEach( item => {
                            if(this.detailParams.applyNo === item.applyNo){
                                this.currentNotice = item;
                                //审批详情页显示对话框
                                this.$Modal.info({
                                    title: '审批消息',
                                    content: this.currentNotice.notice,
                                    okText: '已读',
                                    draggable: true,
                                    onOk: () => {
                                        this.noticeNumberVisible=false;
                                        this.processNotice(this.currentNotice);
                                    }
                                });
                            }
                        });
                    }
                })
            },
            refreshNotice(){
                if(this.isCheck){
                    this.refreshTime = setInterval(() =>{
                        let params={
                            applyNo:this.detailParams.applyNo
                        }
                        getCaseNoticeInfoByApplyNo(params).then((res) => {
                            if(res.code === '0000'){
                                this.noticeInfoList=res.data.records;
                                this.noticeNumber=res.data.total;
                                if(this.noticeNumber > 0){
                                    this.$Message.info("<span style='color: #ed3f14'>有新的审批消息</span>");
                                    this.noticeNumberVisible=true;
                                }else{
                                    this.noticeNumberVisible=false;
                                }
                            }
                        }).catch(() => {
                            clearInterval(this.refreshTime);
                            }
                        );
                    },10000);
                }

            },
            showCaseNotice(){
                clearInterval(this.refreshTime);
                let flag=false;
                this.noticeInfoList.forEach( item => {
                    if(this.detailParams.applyNo === item.applyNo){
                        this.currentNotice = item;
                        flag = true;
                        //审批详情页显示对话框
                        this.$Modal.info({
                            title: '审批消息',
                            content: this.currentNotice.notice,
                            okText: '已读',
                            draggable: true,
                            onOk: () => {
                                this.noticeNumberVisible=false;
                                this.processNotice(this.currentNotice);
                            }
                        });
                    }
                });
                if(!flag){
                    this.$Message.info("没有与当前审批案件相关的消息");
                }
            },
            processNotice(notice){
                markCaseNoticeInfoAsRead(notice).then((res) => {
                    if (res.code === '0000') {
                        console.log("标记成功");
                    }
                });
            }

        },
        mounted() {
            this.getNoticeInfoByApplyNo();
            this.$nextTick(function () {
                this.refreshNotice();
            })
        },
        beforeDestroy(){
            if (this.refreshTime) {
                clearInterval(this.refreshTime);
            }
        },
        created() {
            this.detailParams = this.afs.getPageParams(this);
            this.remindApproveRecord.applyNo = this.detailParams.applyNo;
            this.remindApproveRecord.stageId = this.detailParams.stageId;
            this.isCheck = this.detailParams.isCheck == "true";
            this.isFire = this.detailParams.isFire == "true";
            this.isLung = this.detailParams.isLung == "true";
            this.auditParam.busiNo=this.detailParams.applyNo;
            this.auditParam.belongNo=this.detailParams.applyNo;
            if(this.detailParams.isCheck == "true"){
                this.updateStatusIsOpen();
            }
            if (this.detailParams.businessStateIn !== undefined) {
                this.scene = this.detailParams.businessStateIn
            }
            this.initLinkConfig();
            this.initNewestTortoiseApply();
        }
    };
</script>
